/**
 * Created by thomas on 2017/5/7.
 */
import React,{Component} from 'react';
import { BrowserRouter,Route} from 'react-router-dom';
class RouteWithSubRoutes extends React.Component{
    constructor(props) {
        super(props);
        this.state= {
              pre_d : this.props.pre_dot,
              choice : false

        };
        console.log(this.props.get_dot)
    }
    RouteWithSubRoutes (){
        let _this=this;
        try{
            _this.routes_t=_this.props.route.routes
        }catch (e){
            _this.routes_t={};
             //console.log(_this.props.route)
        }
        sessionStorage.setItem("props",this.props.history);
        //判断 pre_dot
        if(this.state.choice == true){
            return(
                <Route path={this.props.route.path}  render={props =>(
                    // pass the sub-routes down to keep nesting
                    <this.props.route.component {...props} routes={this.routes_t} pre_dot={this.props.pre_dot} get_dot={this.props.get_dot}/>
                )}/>
            )
        }else{
            return(
                <Route path={this.props.route.path}  render={props =>(
                    // pass the sub-routes down to keep nesting
                    <this.props.route.component {...props} routes={this.routes_t}/>
                )}/>
            )
        }

    }
    componentWillMount(){
        if(this.state.pre_d == undefined ){
            this.setState({
                choice : true
            })
        }
    }
    render() {
        return (
            <div>
                {this.RouteWithSubRoutes()}
            </div>
        );
    }
}
// const RouteWithSubRoutes = (route) => (
//     <Route path={route.path} render={props => (
//         // pass the sub-routes down to keep nesting
//         <route.component {...props} routes={route.routes}/>
//     )}/>
// )
export default RouteWithSubRoutes;
